package spring;

import javax.jms.Destination;
import javax.jms.TextMessage;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;

/** 
* @author 朱宏亮
* @version 创建时间：2017年12月7日 下午2:15:20 
* 类说明 
*/
public class ConsumerTopic2 {
    public static void main(String[] args) {  
        ApplicationContext ctx = new ClassPathXmlApplicationContext( "spring/ConsumerTopic2.xml");  

        // 获取JmsTemplate对象  
        JmsTemplate jt = (JmsTemplate) ctx.getBean("jmsTemplate5");  
        
        Destination destination =  (Destination) ctx.getBean("TopicDestination5");  

        while(true){
            TextMessage tm = (TextMessage) jt.receive(destination);
            try {
                
                System.out.println("订阅者2：：" + destination.toString() + "收到了消息：\t" + tm.getText());
         
            } catch (Exception e) {
                //e.printStackTrace();
                System.out.println("暂无消息");
               
            }
        }
    }
}
 